var map, mapCenter;
require([
        "esri/map",
        "esri/layers/ArcGISTiledMapServiceLayer",
        "esri/layers/FeatureLayer",
        "esri/layers/GraphicsLayer",
        "esri/graphic",
        "esri/geometry/Point",
        "esri/symbols/SimpleFillSymbol",
        "esri/symbols/SimpleLineSymbol",
        "esri/symbols/SimpleMarkerSymbol",
        "dojo/_base/Color",
        "esri/tasks/query",
        "esri/tasks/QueryTask",
        "dojo/on",
        "dojo/dom",
        "dojo/domReady!"],
    function(Map,
             Tiled,
             FeatureLayer,
             GraphicsLayer,
             Graphic,
             Point,
             SimpleFillSymbol,
             SimpleLineSymbol,
             SimpleMarkerSymbol,
             Color,
             Query,
             QueryTask,
             on,
             dom)
    {
        map = new Map("map", {logo:false,slider: true});
        var tiled = new Tiled("http://localhost:6080/arcgis/rest/services/chinamap/MapServer");
        map.addLayer(tiled,0);
        var labelLayer = new GraphicsLayer();
        map.addLayer(labelLayer,2);
        mapCenter = new Point(103.847, 36.0473, map.spatialReference);
        map.centerAndZoom(mapCenter,4);
        var city = new FeatureLayer("http://localhost:6080/arcgis/rest/services/city/MapServer/0");
        map.addLayer(city);

        on(dom.byId("query"), "click", function(event){
            map.graphics.clear();
            var name = dom.byId("name").value;
            var query = new Query();
            query.where = "name = '"+name+"'";
            city.queryFeatures(query, function(results) {
                var features = results.features;
                console.log(features);
                map.centerAndZoom(features[0].geometry,8);
                var sms = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND,
                    10,
                    new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                        new Color([0,0,0]),
                        1
                    ),
                    new Color([255,0,0])
                );
                map.graphics.add(new Graphic(features[0].geometry,sms));
            });
        });

        var draw = new esri.toolbars.Draw(map);
        draw.on("draw-end",addGraphicToMap);
        on(dom.byId("extent"), "click", function(event){
            map.graphics.clear();
            map.setMapCursor("pointer");
            draw.activate(esri.toolbars.Draw.EXTENT);
        });
        function addGraphicToMap(evt){
            map.setMapCursor("default");
            draw.deactivate();
            var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
                new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
                    new Color([255,0,0]),
                    2
                ),
                new Color([255,255,0,0.25])
            );
            map.graphics.add(new Graphic(evt.geometry, sfs));
            //根据空间进行查询
            var query = new Query();
            query.geometry = evt.geometry;
            city.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){
                console.log(results);
